package com.kingbook.common.sender;

import com.alibaba.fastjson.JSONObject;
import com.kingbook.common.net.RestfulClient;
import org.springframework.beans.factory.annotation.Value;

/**
 */
public class SMSSendUtil {

    static String sendTextSmsUrl;

    static String sendTemplateSmsUrl;

    @Value("${sms.send.text.url}")
    public void setSendTextSmsUrl(String textSmsUrl) {
        sendTextSmsUrl = textSmsUrl;
    }

    @Value("${sms.send.template.url}")
    public void setSendTemplateSmsUrl(String templateSmsUrl) {
        sendTemplateSmsUrl = templateSmsUrl;
    }


    public static String sendTextSms(String appCode, String phones, String content){
        JSONObject body = new JSONObject();
        body.put("appCode", appCode);
        body.put("phones", phones);
        body.put("content",content );
        return RestfulClient.postAsJson(sendTextSmsUrl,null,null,body.toJSONString());
    }

    public static String sendTemplateSms(String appCode, String phones,String templateId, String[] params){
        JSONObject body = new JSONObject();
        body.put("appCode", appCode);
        body.put("phones", phones);
        body.put("templateId",templateId );
        body.put("params",params );
        return RestfulClient.postAsJson(sendTemplateSmsUrl,null,null,body.toJSONString());
    }

}
